<html lang="zh-cn">
  
  <head></head>
  <meta http-equiv=Content-Type content=text/html;charset=UTF-8>
  <script type="text/javascript">
      var childsJson = {
        "class-2-1": {
          "name": "中一班",
          "childs": "彭芝源,桂梓轩,陈瑞森,吴浥尘,韩沐瑶,王高乐,兰锦鹏,刘哲宇,彭多米,马姜,邹馨宁,李奇林,熊彦羽,刘玺轩,徐思妍,王梓楠,郭致远,吴依遥,范跃程,黄诗颖,严雨昕,王若伊,肖梓宁,陈蔚宁,尹伊然,郭一玚,祝子彤,江艺馨,王凯鑫,韦铃悦,李筱"
        },
        "class-2-2": {
          "name": "中二班",
          "childs": "罗文悦,张悦涵,李嘉文,高婕雯,钟广毅,屠成宜,陈奕均,赖云晗,沈梓添,苏诗月,杨皓晨,秦宇潇,岳巨梓乐,黄钰轩,高子皓,陈慕阳,冯楷信,刘恺俊,蒋语阳,李思路,万昱圻,杨籽玲,杜蒲映姗,陈峻熙,廖宸悠,李璟岐,甘宇宸,梁佳悦,李林雨杭,李彬睿"
        },
        "class-2-3": {
          "name": "中三班",
          "childs": "林一,梁梓文,王知翊,吴云帆,周真竹,万天思岑,徐思琪,陈洛言,杜宜诺,周敬尧,文一朵,王星惟,杜家辉,陈峒羽,张奕楠,张曦予,何彦辰,刘梓涵,杜禹泽,罗文汐,兰雨泽,谢菀宸,洪星,杨宜果,杜悦然,宋雨牧,贾鸿轩,伍君宇,肖艺萱,陈博文,张赞宇"
        },
        "class-1-2": {
          "name": "小二班",
          "childs": "乔琳涵,杜曼琳,梁骄灵,邓伊辰,谭力,张槿芸,易卓凡,陈璟橙,唐希芮,鲍继乾,张嘉恒,李彦杰,丁语偲,朱浩铭,胡杰豪,邓棋允,陶言蹊,陈泓宇,肖俊霖,孙琳雅,许轩齐,周宇皓,张嘉朗,杨子赫,谭知言,周雨萱,王程萱,杨佳乐,刘佳仪,黄承宇"
        }
      };

var child = childsJson["class-2-1"];

window.onload = function() {
      fullChildName();
      var select = "<option>请选择班级</option><br/>";
      for (key in childsJson) {
        var name = childsJson[key]["name"];
        select += "<option value=" + key + ">" + name + "</option><br/>";
        //console.log(key + name);
      }
      document.getElementById("childSelect").innerHTML = select;


    }
    function selectClass() {
   var option = document.getElementById("childSelect").value;
child = childsJson[option];
fullChildName(child);
}

function fullChildName(){
	var childName = child == undefined ? "":(child['childs'] == undefined ? "":child['childs']);
	document.getElementById("childName").value = childName;
}
    function filter() {
      var childNameStr = document.getElementById("childName").value;
      if (childNameStr == undefined || childNameStr == "") {
      document.getElementById("noJieLong").innerHTML = "";
      document.getElementById("count").innerHTML = "";
        alert("输入娃儿名字");
        return false;
      }
      var childs = childNameStr.trim().split(",");
      var jielong = document.getElementById("jieLong").value;
      var parents = [];
      var noJieLong = "";
      childs.forEach(function(item, index) {
        if (jielong.indexOf(item) == -1) {
          parents.push(item);
          noJieLong += item + "<br/>"
        }
      });
      document.getElementById("noJieLong").innerHTML = noJieLong;
      document.getElementById("count").innerHTML = "共有" + childs.length + "个娃娃，已有" + (childs.length - parents.length) + "个娃娃接龙，还有" + parents.length + "个娃娃没有接龙。";
    }</script>
  
  <body>
    <div>
      <select onChange="javascript:selectClass()" id="childSelect"></select>
    </div>
    <div>
      <span>幼儿名字(名字以逗号隔开)：</span>
      <br/>
      <textarea placeholder="幼儿名字(名字以逗号隔开)" id="childName" name="childName" cols="90" rows="10"></textarea></div>
    <div>
      <span>家长接龙：</span>
      <br/>
      <textarea id="jieLong" name="jieLong" cols="90" rows="15"></textarea>
    </div>
    <div width="100%" style="text-align:center;">
      <button value="筛选" onClick="javascript:filter()">筛选</button></div>
    <div>
      <span>未接龙家长：
        <span id="count"></span></span>
      <br/>
      <br/>
      <div id="noJieLong"></div>
    </div>
  </body>

</html>